package com.atguigu.springcloud.controller;


import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@RequestMapping("/consumer/payment")
public class OrderController {
    /**
     * 日志配置
     */
    private Logger logger = LoggerFactory.getLogger(OrderController.class);

    /**
     * 请求路径
     */
    private static final String URL = "http://localhost:8001";
    /**
     * RestTemplate
     */
    @Resource
    private RestTemplate restTemplate;
    /**
     * 创建
     * @return
     */
    @PostMapping("/create")
    public CommonResult<Payment> create(Payment payment){
        logger.info("请求进入");
        return restTemplate.postForObject(URL+"/payment/create",payment,CommonResult.class);
    }

    @GetMapping("/get/{id}")
    public CommonResult<Payment> get(@PathVariable("id") Long id){
        logger.info("请求进入");
        return restTemplate.getForObject(URL+"/payment/get/"+id,CommonResult.class);
    }
}
